<?php

namespace app\api\controller\v1;

use app\api\validate\IDMustBePositiveInt;
use app\api\validate\IDCollection;
use app\api\model\Theme as ThemeModel;
use app\lib\exception\ThemeException;

class Theme {
    /**
     * @url /theme?ids=id1,id2,id3,...
     * @返回 一组theme模型
     * **/
    public function getSimpleList($ids=''){
        (new IDCollection())->goCheck($ids);
        $ids = explode(',', $ids);  //将其转换为数组
        $result = ThemeModel::with(['topicImg','headImg'])
                ->select($ids);
        if(!$result){
            throw new ThemeException();
        };
        return $result;
    }


    /**
     * @url /theme/:id
     * **/
    public function getComplexOne($id){
        //校验id是必须的
        (new IDMustBePositiveInt())->goCheck();
        $theme = ThemeModel::getThemeWithProducts($id);
        if(empty($theme)){
            throw new ThemeException();
        };
        return $theme;
    }
}
